package com.halixun.d2app.dialog;


import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.halixun.d2app.R;
import com.halixun.d2app.utils.ToastUtils;

/**
 * A simple {@link Fragment} subclass.
 */
public class ReminderFragment extends DialogFragment implements View.OnClickListener {

    public static final String KEY_PARAMS = ReminderFragment.class.getSimpleName()+"key_params";

    public static ReminderFragment getInstance(String title){
        if (title==null){
            title = "";
        }
        ReminderFragment f = new ReminderFragment();
        Bundle params = new Bundle();
        params.putString(KEY_PARAMS,title);
        f.setArguments(params);
        return f;
    }

    public ReminderFragment() {
        // Required empty public constructor
    }

    private TextView mTitle;

    private String title;

    private ReminderListener mListener;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        title = getArguments().getString(KEY_PARAMS);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_reminder, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        setListeners(view);
    }

    private void setListeners(View view) {
        view.findViewById(R.id.confirm).setOnClickListener(this);
        view.findViewById(R.id.cancel).setOnClickListener(this);
    }

    private void initView(View view) {
        mTitle = view.findViewById(R.id.title);
        mTitle.setText(title);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.confirm:
                if (null!=mListener){
                    mListener.onReminderListener();
                }
            case R.id.cancel:
                dismiss();
                break;
        }
    }

    public void setReminderListener(ReminderListener listener){
        this.mListener = listener;
    }

    public interface ReminderListener{
        void onReminderListener();
    }

}
